#include <iostream>
#include <vector>
using namespace std;
vector<int> a;
vector<int> cha;
int x;
int main() {
    cin >> x;
    for(int i = 0; i < x; i++) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    cha.resize(a.size());
    cha[0] = a[0];
    int ans = 0;
    for(int i = 1; i < a.size(); i++) {
        cha[i] = a[i] - a[i - 1];
        if(cha[i] > 0) {
            ans += cha[i];
        }
    }
    cout << ans + cha[0] << endl;
    return 0;
}